<template>
	<view class="box">
		<view class="" style="width: 100%;text-align: center;padding-top: 390rpx;position: relative;">
			<image src="https://web.78keji.cn/newimgaes/nologins.png" mode="widthFix" style="width:543rpx;"
				v-if="flag==1||flag==-1"></image>


			<image src="../../static/yijian.png" mode="widthFix" style="width: 397rpx;margin-top: 71rpx;"
				v-if="flag==1"></image>
			<view class="d_f j_c_c">
				<button class="login" @error="onAuthError" type="default" open-type="getAuthorize"
					@getAuthorize="onGetAuthorize" scope='phoneNumber'
					style="position: absolute;width: 397rpx;height: 96rpx;margin-top: -126rpx;opacity: 0;"
					v-if="flag==1"></button>
				<view class="" v-if="flag=='-1'"
					style="width: 397rpx;margin-top: 20rpx;border-radius: 40rpx;overflow: hidden;">
					<u-input v-model="mobile" maxlength="11" type="number" placeholder="输入手机查看"
						style="position: absolute;height: 96rpx;"></u-input>
				</view>


			</view>
			<view class="d_f a_i_c j_c_c" v-if="flag=='-1'" style="margin-top: 10rpx;">
				<view class="qd" @click="qd">
					确定
				</view>
			</view>

		</view>



	</view>
</template>

<script>
	import {

		openSignDecrypt,
		bindMobile,
		ljjQuery,
		ljjList,
		getMpUrl


	} from '../../api/index.js'
	import md5 from '@/utils/md5.js'
	export default {
		data() {
			return {
				flag: '0',
				mobile: ""
			}
		},
		components: {

		},
		methods: {
			qd() {
				if (!/^1[3456789]\d{9}$/.test(this.mobile)) {
					// 手机号格式不正确，提示用户
					wx.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					});
				} else {
				uni.setStorageSync('mobile', this.mobile)
				uni.setStorageSync('openid', md5.hex_md5(uni.getStorageSync('mobile') + '456'))
				ljjList({
					openid:uni.getStorageSync('openid'),
					type:'3',
					proType:'5',
					}).then((result)=>{
					console.log(result)
					if(result.data==null||result.data==''||result.data==[]){
						uni.reLaunch({
							url:'/pages/ncheck/ncheck'
						})
					}else{
					var ret = result.data.every(function(elem,index,array){
					
					    console.log(elem.status);
					    return elem.status==1||elem.status==3||elem.status==4||elem.status==6;
					});
					if(ret==false){
						uni.navigateTo({
							url:'/pages/ljjlq/ljjlq'
						})
					}else{
						uni.navigateTo({
							url:'/pages/ncheck/ncheck'
						})
					}
					}
				})
				}

			},
			onAuthError() {
				console.log('拒绝授权')
				this.flag = '-1'
			},
		
			onGetAuthorize() {
				uni.showLoading({
					title: "授权中",
					mask: true
				})
				my.getPhoneNumber({
					success: (res) => {
						let encryptedData = res.response;
						console.log(encryptedData)
						openSignDecrypt({
							encryptedData: JSON.parse(encryptedData).response,
							xcx: 3
						}).then((resx) => {
							console.log(resx)
							uni.setStorageSync('mobile', resx.data.mobile)
							uni.setStorageSync('openid', resx.data.openid)
							this.mobile = resx.data.mobile
							this.openid = resx.data.openid
						
							ljjList({
								openid:uni.getStorageSync('openid'),
								type:'3',
								proType:'5',
								}).then((result)=>{
								console.log(result.data,777)
								if(result.data==null||result.data==''||result.data==[]){
									uni.reLaunch({
										url:'/pages/ncheck/ncheck'
									})
								}else{
								var ret = result.data.every(function(elem,index,array){
								
								    console.log(elem.status);
								    return elem.status==1||elem.status==3||elem.status==4||elem.status==6;
								});
								if(ret==false){
									uni.navigateTo({
										url:'/pages/ljjlq/ljjlq'
									})
								}else{
									uni.navigateTo({
										url:'/pages/ncheck/ncheck'
									})
								}
								}
							})
							uni.hideLoading()
							my.getAuthCode({
								scopes: 'auth_base',
								success: (res) => {
									console.log(res)
									my.request({
										url: 'https://www.sx2b2c.com/api/rf/getAliUserid', // 请求的 URL
										method: 'POST', // POST 方法
										data: {
											code: res.authCode,
											pro_id: 2014
										},
										header: {
											'Content-Type': 'application/x-www-form-urlencoded' // 设置请求头
										},
										success: (result) => {
											this.showqd = true
											this.showsq = false
											bindMobile({
												mobile: this.mobile,
												user_id: result.data
													.data.user_id
											}).then((res) => {
												console.log(res)
											})
											my.setStorageSync({
												key: 'user',
												data: result.data.data
													.user_id
											})

										},
										fail: function() {

										}
									})

								},
							});

						})

					},
					fail: (res) => {
						console.log(res);
						uni.hideLoading()
						console.log('getPhoneNumber_fail');
					},
				});


			},
		},
		onShow() {

		},
		onLoad(option) {
			console.log(md5.hex_md5('15988604696' + '456'))
			if (option.mobile) {
				uni.setStorageSync('mobile', option.mobile)
				uni.setStorageSync('openid', md5.hex_md5(option.mobile + '456'))
				ljjList({
					openid:uni.getStorageSync('openid'),
					type:'3',
					proType:'5',
					}).then((result)=>{
					console.log(result,99999)
					if(result.data==null||result.data==''||result.data==[]){
						uni.reLaunch({
							url:'/pages/ncheck/ncheck'
						})
					}else{
					var ret = result.data.every(function(elem,index,array){
					
					    console.log(elem.status);
					    return elem.status==1||elem.status==3||elem.status==4||elem.status==6;
					});
				
					if(ret==false){
						uni.navigateTo({
							url:'/pages/ljjlq/ljjlq'
						})
					}else{
						
						uni.navigateTo({
							url:'/pages/ncheck/ncheck'
						})
					}
					}
				})

			} else {
				this.flag = '1'
			}
			if (option.a) {
				uni.setStorageSync('a', option.a)
				
			}



	getMpUrl({
				env: 23,
				a: uni.getStorageSync('a')
			}).then((res) => {

			})
		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style scoped>
	.qd {
		width: 397rpx;
		height: 76rpx;
		background: linear-gradient(-90deg, #1E7AFF, #65A1FF);
		color: white;
		line-height: 76rpx;
		border-radius: 43rpx;
	}
</style>